package com.ssm.controller;

import com.ssm.domain.User;
import com.ssm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author wangLin
 * @version 1.0
 * @projectName maven-ssm-wl
 * @className UserController
 * @date 2021-03-16 周二
 * @time 18:16
 * @description TODO
 */

@Controller
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/index")
    public ModelAndView index() {
        String view = "index";
        ModelAndView modelAndView = new ModelAndView(view);
        return modelAndView;
    }

    @RequestMapping("/registerIndex")
    public ModelAndView registerIndex() {
        String view = "registerIndex";
        ModelAndView modelAndView = new ModelAndView(view);
        return modelAndView;
    }

    /**
     * 登录
     *
     * @param user
     * @return
     */
    @RequestMapping("/login")
    public ModelAndView login(User user) {
        String view = "login_fail";
        if (userService.login(user)) {
            view = "login_succ";
        }
        ModelAndView modelAndView = new ModelAndView(view);
        return modelAndView;

    }

    /**
     * 注册
     *
     * @param user
     * @return
     */
    @RequestMapping("/register")
    public ModelAndView register(User user) {
        String view = "register_succ";
        userService.insertUser(user);
        ModelAndView modelAndView = new ModelAndView(view);
        return modelAndView;
    }

}
